import axios from 'axios'

const API_URL = process.env.VUE_APP_API_URL || 'http://localhost:3000/api'

export const authService = {
  async login({ username, password }) {
    // 模拟登录
    await new Promise((resolve) => setTimeout(resolve, 500))
    // 实际项目应调用后端API
    return {
      user: {
        id: 1,
        username,
        email: username + '@example.com',
        role: username === 'admin' ? 'admin' : 'user',
        avatar: '',
        bio: '',
      },
      token: 'mock-token',
    }
  },
  async register({ username, email, password }) {
    await new Promise((resolve) => setTimeout(resolve, 500))
    return {
      user: {
        id: 2,
        username,
        email,
        role: 'user',
        avatar: '',
        bio: '',
      },
      token: 'mock-token',
    }
  },
  async logout() {
    await new Promise((resolve) => setTimeout(resolve, 200))
    return true
  },
  async getCurrentUser() {
    await new Promise((resolve) => setTimeout(resolve, 200))
    return {
      id: 1,
      username: 'admin',
      email: 'admin@example.com',
      role: 'admin',
      avatar: '',
      bio: '管理员',
    }
  },
  async updateProfile(userData) {
    await new Promise((resolve) => setTimeout(resolve, 500))
    return {
      ...userData,
      id: 1,
      role: 'admin',
    }
  },
}
